using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TMS.Application.Common.Interface;
using TMS.Application.RequestDto;
using TMS.Domain.Entity;

namespace TMS.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class QuickController : ControllerBase
    {
        private readonly IRepository<StuUsers> _StuUsers;
        private readonly IRepository<Students> _Students;


        public QuickController(IRepository<StuUsers> StuUsers, IRepository<Students> Students)
        {
            _Students = Students;
            _StuUsers = StuUsers;

        }
        //添加学生用于测试
        [HttpPost("/add")]
        public async Task<string> AddStudent()
        {
            var m = _StuUsers.Table.Where(x => x.UserId == "006").ToList();
            if (m.Count == 0)
            {
                //只是测试数据库student登录
                var stu = new StuUsers()
                {
                    UserId = "666",
                    PassWord = "113",
                    AvatarId = new Guid("4b5346bb-4a13-4f5d-a209-1558a5c394d5")
                };

                await _StuUsers.AddAsync(stu);
                var stu2 = new Students()
                {
                    StudentId = stu.UserId,
                    StudentName = "aaa",
                    // Sex='m',

                };

                await _Students.AddAsync(stu2);
                return "添加成功";
            }else
            {
                return "以有该学生";
            }

        }

        [HttpPost("/del")]
        public async Task<string> DelStudent()
        {//快速删除student所有数据
            var stu = _Students.Table.ToList();
            var s = _StuUsers.Table.ToList();
            await _Students.DeleteBulkAsync(stu, true);
            await _StuUsers.DeleteBulkAsync(s, true);
            return "删除成功";

        }

        [HttpGet("/s")]
        public object s()
        {
            var s= _Students.Table.ToList();
            return new
            {
                code=200,
                msg="全部学生",
                data=s
            };
        }
    }
}